package com.zhuss.want.processor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.SearchKeyWordBo;
import com.zhuss.bean.bo.want.want.SearchWantBo;
import com.zhuss.bean.bo.want.want.wechat.ListWantBo;
import com.zhuss.bean.vo.DetailKeyWordVo;
import com.zhuss.bean.vo.want.want.DetailWantVo;
import com.zhuss.bean.vo.want.want.ListWantVo;
import com.zhuss.want.db.dao.ext.WantDao;
import com.zhuss.want.db.entity.Want;
import com.zhuss.common.PageVo;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.exception.WpsException;


/**
 * 查询求职 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("wantRead")
public class WantRead {
	
	@Autowired
	private WantDao wantDao;
	
	/**
	 * 求职 
	 * @return
	 */
	public Object listWantId(Integer area) {
		List<Want> wantList = wantDao.listAll(area);
		List<Long> result = new ArrayList<>();
		transferListId(wantList, result);
		return result;
	}
	
	
	/**
	 * keyWord
	 * @param bo
	 * @return
	 */
	public PageVo<DetailKeyWordVo> keyWord(SearchKeyWordBo bo) {
		PageVo<DetailKeyWordVo> result = new PageVo<DetailKeyWordVo>();
		List<DetailKeyWordVo> list = new ArrayList<DetailKeyWordVo>();
		list = wantDao.keyWord(bo);
		Integer count = wantDao.countKeyWord(bo);
		result.setPageNum(bo.getPageNum());
		result.setPageSize(bo.getPageSize());
		result.setTotal(count);
		result.setItems(list);
		return result;
	}
	
	
	/**
	 * 求职列表
	 * @param bo
	 * @return
	 */
	public Object listWant(ListWantBo bo) {
		PageVo<DetailWantVo> result = new PageVo<DetailWantVo>();
		List<DetailWantVo> list = new ArrayList<DetailWantVo>();
		list = wantDao.listWant(bo);
		Integer count = wantDao.countWantList(bo);
		result.setPageNum(bo.getPageNum());
		result.setPageSize(bo.getPageSize());
		result.setTotal(count);
		result.setItems(list);
		return result;
	}
	
	private void transferListId(List<Want> wantList, List<Long> result) {
		for (Want item : wantList) {
			result.add(item.getWantId());
		}
	}

	/**
	 * 求职列表
	 * @param bo
	 * @return
	 */
	public Object list(SearchWantBo bo) {
		PageVo<ListWantVo> result = new PageVo<ListWantVo>();
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(wantDao.list(bo));
        result.setTotal(wantDao.countList(bo));
		return result;
	}
	
	/**
	 * 求职详情
	 * @param wantId
	 * @return
	 * @throws WpsException
	 */
	public Object detail(Long wantId) throws WpsException {
		Object result = wantDao.detail(wantId);
		if (result == null) {
			throw new WpsException(ExceptionCode.数据不存在);
		}
		return result;
	}
	
	

}
